//
//  UINavigationController+AOP.m
//  03-权限控制
//
//  Created by 哲 肖 on 15/11/20.
//  Copyright (c) 2015年 肖喆. All rights reserved.
//

#import "UINavigationController+AOP.h"
#import "NSObject+AOP.h"
#import "LoginController.h"
@implementation UINavigationController (AOP)

+(void)load
{
    [UINavigationController aop_exchangeMethodIMP:@selector(pushViewController:animated:) newSelector:@selector(aop_pushViewController:animated:)];

}

- (void)aop_pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    NSString * path = [[NSBundle mainBundle] pathForResource:@"Autority.plist" ofType:nil];
    NSArray * classNames = [NSArray arrayWithContentsOfFile:path];//@[@"GPHomeDetailController",@"GPMineDetailViewController"];
    
    for(NSString * tmp in classNames)
    {
        
        if([tmp isEqualToString:NSStringFromClass([viewController class])])
        {
//            NSLog(@"%@ claaName",NSStringFromClass([viewController class]));
            
            //1.
            NSUserDefaults * udf = [NSUserDefaults standardUserDefaults];
            NSString * name = [udf objectForKey:@"name"];
//            NSLog(@"%@",name);
            
            if(name == nil || name.length < 6)
            {
                
                LoginController * loginViewController = [[LoginController alloc] init];
                
//                UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:loginViewController];
                
                [self presentViewController:loginViewController animated:YES completion:nil];
                
                return;
            }
        }//end if
        
        

    }//end for
    
    
    
    //执行真正的原有的push方法
    [self aop_pushViewController:viewController animated:animated];
    

}//end method

@end
